package com.recipe.controller;


import com.alibaba.fastjson.JSON;
import com.recipe.common.entity.Result;
import com.recipe.entity.DishLiked;
import com.recipe.entity.vo.DishVo;
import com.recipe.service.DishLikedService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * (DishLiked)表控制层
 *
 * @author lzk
 * @since 2024-06-18 09:24:27
 */
@RestController
@RequestMapping("dishLiked")
@RequiredArgsConstructor
@Slf4j
public class DishLikedController {
    private final DishLikedService dishLikedService;

    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody DishLiked dishLiked) {

        if (log.isInfoEnabled()) {
            log.info("DishLikedController.add:{}", JSON.toJSONString(dishLiked));
        }

        dishLikedService.add(dishLiked);
        return Result.ok();
    }

    @PostMapping("/deleteById")
    public Result<Boolean> deleteById(@RequestBody DishVo dishVo) {

        if (log.isInfoEnabled()) {
            log.info("DishLikedController.deleteById:{}", JSON.toJSONString(dishVo));
        }

        dishLikedService.deleteById(dishVo);
        return Result.ok();

    }

    @GetMapping("/getLikedCount/{dishId}")
    public Result<Integer> getLikedCount(@PathVariable Long dishId) {

        if (log.isInfoEnabled()) {
            log.info("DishLikedController.getLikedCount:{}", JSON.toJSONString(dishId));
        }
        return Result.ok(dishLikedService.getLikedCount(dishId));
    }

    @GetMapping("/isLiked/{dishId}/{userId}")
    public Result<Boolean> isLiked(@PathVariable String dishId, @PathVariable String userId) {

        if (log.isInfoEnabled()) {
            log.info("DishLikedController.isLiked:{},{}", JSON.toJSONString(dishId), JSON.toJSONString(userId));
        }
        return Result.ok(dishLikedService.isLiked(dishId, userId));
    }




}

